package com.example.a33mvvm.login;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;

import com.example.base_mvvm.base.BaseViewModel;
import com.example.base_mvvm.entity.LoginEntity;
import com.example.base_mvvm.net.Const;
import com.google.gson.Gson;

import java.util.HashMap;

import okhttp3.MediaType;
import okhttp3.RequestBody;

public class LoginViewModel extends BaseViewModel<LoginRepo> {
    public MutableLiveData<LoginEntity> success = new MutableLiveData<>();
    public MutableLiveData<String> failure = new MutableLiveData<>();
    public LoginViewModel(@NonNull Application application) {
        super(application);
    }
    public void login(String username,String password){
        HashMap<String, String> map = new HashMap<>();
        map.put(Const.USERNAME,username);
        map.put(Const.PASSWORD,password);
        String json = new Gson().toJson(map);
        RequestBody body = RequestBody.create(MediaType.parse(Const.PARSE),json);
        repo.login(body,success,failure);
    }

    @Override
    protected LoginRepo createRepo() {
        return new LoginRepo();
    }

}
